<?php
require 'Controller.php';
require 'Home/Model/HouseModel.php';

class HouseController extends Controller{
    function __construct()
    {
        parent::__construct();
    }

    function HouseForm(){
        require 'Home/View/houseadd.php';
    }

    function HouseAdd(){
        $h_model=new HouseModel();
        $result=$h_model->addhouse();
        if($result) {
            parent::redirect("index.php","添加成功!返回首页");
        } else {
            parent::redirect("index.php?c=house&m=HouseForm","添加失败!重新提交");
        }
    }

    function House(){
        $housemodel = new HouseModel();
        $data = $housemodel->getHouseList();

        include 'Home/View/houselist.php';
    }

    function Housedetail(){
        $id = $_GET['id'];

        $housemodel = new HouseModel();
        $data = $housemodel->getHouse($id);

        include 'Home/View/house.php';
    }

    function search(){
        $key = $_POST['key'];
        $housemodel=new HouseModel();
        $data=$housemodel->getuserinfro($key);

        include 'Home/View/houselist.php';
    }

    function changestatus1(){
        $hid = $_GET['hid'];
        $housemodel = new HouseModel();
        $result = $housemodel->changestatus1($hid);
        if($result) {
            parent::redirect("index.php?c=House&m=House","租房成功!,请等待卖家与你联系！");
        } else {
            parent::redirect("index.php?c=House&m=Housedetail&id='.$hid.'","租房失败!,重新租房！");
        }
    }

    function changestatus2(){
        $hid = $_GET['hid'];
        $housemodel = new HouseModel();
        $result = $housemodel->changestatus2($hid);
        if($result) {
            parent::redirect("index.php?c=House&m=House","购房成功!,请等待卖家与你联系！");
        } else {
            parent::redirect("index.php?c=House&m=Housedetail&id='.$hid.'","购房失败!,重新租房！");
        }
    }

    function houselist(){
        $uname =$_GET['uname'];
        $housemodel = new HouseModel();
        $uid = $housemodel->getUidByUname($uname);
        $data = $housemodel->getbuyerhouselist($uid);

        include 'Home/View/buyerhouselist.php';
    }

    function housedel(){
        $id = $_GET['id'];
        $housemodel = new HouseModel();
        $result = $housemodel->dodeletehouse($id);
        if($result){
            parent::redirect("index.php?c=house&m=houselist&uname=".$_SESSION['user'],"删除成功！");
        } else {
            parent::redirect("index.php?c=house&m=houselist&uname=".$_SESSION['user'],"删除失败！请重新删除");
        }
    }

    function houseeditform(){
        $id = $_GET['id'];
        $housemodel = new HouseModel();
        $data = $housemodel->getHouse($id);

        include 'Home/View/houseedit.php';
    }

    function housemod(){
        $uname = $_SESSION['user'];
        $id = $_POST['id'];
        $housemodel = new HouseModel();
        $result = $housemodel->dohousemod($id);

        $uid = $housemodel->getUidByUname($uname);
        $data = $housemodel->getbuyerhouselist($uid);
        if($result){
            include 'Home/View/buyerhouselist.php';
            //parent::redirect("index.php?c=house&m=houselist&uname=".$_SESSION['user'],"修改成功！");
        } else {
            parent::redirect("index.php?c=house&m=houseeditform&id=".$id,"修改失败！请重新修改");
        }
    }
}
?>